#ifndef MCLEANER_HPP
#define MCLEANER_HPP

#ifndef _UNICODE
#define _UNICODE
#endif //_UNICODE

/************* WXWIDGETS STUFF *********/
#include <wx/wxprec.h>  //precompiled things

#ifndef WX_PRECOMP              //in case no precompiled things
#include <wx/wx.h>
#endif //WX_PRECOMP

#include <wx/aboutdlg.h>
#include <wx/cmdline.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <wx/generic/dirctrlg.h>
#include <wx/icon.h>
#include <wx/listctrl.h>
#include <wx/progdlg.h>
#include <wx/radiobut.h>
#include <wx/stdpaths.h>
/******** END WXWIDGETS STUFF ***********/

#include <algorithm> //sort
#include <fstream>
#include <vector>

#include "asset.hpp"
#include "filename.hpp"
#include "filereader.hpp"

// default window size 
#define HORSIZE 900
#define VERSIZE 600
static const wxString MCVERSION = wxT("0.7 beta");

class MCleanApp: public wxApp
{
public:
  virtual bool OnInit();
  virtual void OnInitCmdLine(wxCmdLineParser &parser);
  virtual bool OnCmdLineParsed(wxCmdLineParser &parser);

  //Program settings
  bool app_out;
  wxString app_StartMod;
};

class MyFrame: public wxFrame
{
public:
  MyFrame(const wxString &title, const wxSize &size, wxString StartMod);

private:
  void OnClear    (wxCommandEvent &event);
  void OnAbout    (wxCommandEvent &event);
  void OnQuit     (wxCommandEvent &event);

  void OnSelected (wxListEvent    &event);
  void OnModeFX   (wxCommandEvent &event);
  void OnModeMP   (wxCommandEvent &event);
  void OnCheckThis(wxCommandEvent &event);
  void OnOutfile  (wxCommandEvent &event);

  //UI elements
  wxArrayString *ModeAS;
  wxBoxSizer *CentreSizer;
  wxButton *do_curmod, *do_outfile;
  wxFlexGridSizer *Miscgrid;
  wxGenericDirCtrl *Dirpanel;
  wxGridSizer *VertiSizer, *ModeSizer;
  wxListCtrl *FindAsset;
  wxMenu *menuFile;
  wxMenuBar *menuBar;
  wxPanel *MainPanel;
  wxProgressDialog *bardlg;
  wxRadioButton *ModeFX, *ModeMP;
  wxSizerFlags *FixedFlags, *ExpandFlags;
  wxStaticBoxSizer *FindBox;
  wxTextCtrl *Logpanel, *Usedpane;

  //Program settings
  bool verbose;
  int findboxmode;

  //Data
  wxFileName datadir;
  std::vector<Asset> AllMaps;
  std::vector<Asset> AllFX;       
  std::vector<wxString>unusedmaps; // unused maps, with extensions
  std::vector<wxString>unusedfx;

  //Assistant functions
  void addEffectUser  (wxString User, std::vector <wxString> Using);
  void addMapUser     (wxString User, std::vector <wxString> Using);
  void writeFindAsset (std::vector <Asset> WriteThis);
  void reset          ();

  DECLARE_EVENT_TABLE()
};

enum //ID for all relevant controls
  {
    // misc pane
    ID_OUTFILE,
    ID_CHECKTHIS,

    // FindBox
    ID_MODE_FX,
    ID_MODE_MP,
    ID_SELECTED,

    // menu items & controls
    ID_CLEAR,
    ID_Quit = wxID_EXIT,
    ID_About = wxID_ABOUT,
  };

enum // Modes of FindBox sizer
  {
    MODE_FX,
    MODE_MP,
  };

static const wxCmdLineEntryDesc g_cmdLineDesc [] = 
  {// allowed command-line arguments

#if (wxMAJOR_VERSION >= 3 || (wxMAJOR_VERSION == 2 && wxMINOR_VERSION == 9))
    //wxWidgets 2.9 or higher

    {wxCMD_LINE_SWITCH, "h", "help",
     "Displays help on mcleaner command-line parameters",
     wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
    {wxCMD_LINE_OPTION, "m", "mod",
     "Starts with the given mod folder selected"},

#else //wxWidgets 2.8 or earlier

    {wxCMD_LINE_SWITCH, wxT("h"), wxT("help"),
     wxT("Displays help on mcleaner command-line parameters"),
     wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP},
    {wxCMD_LINE_OPTION, wxT("m"), wxT("mod"),
     wxT("Starts with the given mod folder selected")},

#endif

    {wxCMD_LINE_NONE}
  };

bool compareAssets (Asset One, Asset Two);

BEGIN_EVENT_TABLE (MyFrame, wxFrame)
EVT_BUTTON (ID_OUTFILE, MyFrame::OnOutfile)
EVT_BUTTON (ID_CHECKTHIS, MyFrame::OnCheckThis)
EVT_LIST_ITEM_SELECTED (ID_SELECTED, MyFrame::OnSelected)
EVT_RADIOBUTTON (ID_MODE_FX, MyFrame::OnModeFX)
EVT_RADIOBUTTON (ID_MODE_MP, MyFrame::OnModeMP)

EVT_MENU (ID_CLEAR, MyFrame::OnClear)
EVT_MENU (ID_Quit, MyFrame::OnQuit)
EVT_MENU (ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

#endif //MCLEANER_HPP
